home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / gfx / nsTransform2D.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  7KB  |  259 lines

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  26.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. #ifndef nsTransform2D_h___
  39. #define nsTransform2D_h___
  40.  
  41. #include "gfxCore.h"
  42. #include "nsCoord.h"
  43. #include "nsUnitConversion.h"
  44.  
  45. #define MG_2DIDENTITY     0
  46. #define MG_2DTRANSLATION  1
  47. #define MG_2DSCALE        2
  48. #define MG_2DGENERAL      4
  49.  
  50. class NS_GFX nsTransform2D
  51. {
  52. private:
  53.   //accelerators
  54.  
  55.   float     m00, m01, m10, m11, m20, m21;
  56.   PRUint16  type;
  57.  
  58. public:
  59.   //constructors
  60.  
  61.   nsTransform2D(void)                         { SetToIdentity(); }
  62.   nsTransform2D(nsTransform2D *aTransform2D)  { SetMatrix(aTransform2D); }
  63.  
  64.   //destructor
  65.  
  66.   ~nsTransform2D(void)                        { }
  67.  
  68.  /**
  69.   * get the type of this transform
  70.   *
  71.   * @param
  72.   * @return     type from above set
  73.   * @exception
  74.   * @author     michaelp   09-25-97 1:56pm
  75.   **/
  76.  
  77.   PRUint16 GetType(void)                      { return type; }
  78.  
  79.  /**
  80.   * set this transform to identity
  81.   *
  82.   * @param
  83.   * @exception
  84.   * @author     michaelp   09-25-97 1:56pm
  85.   **/
  86.  
  87.   void SetToIdentity(void)                    { m01 = m10 = m20 = m21 = 0.0f; m00 = m11 = 1.0f; type = MG_2DIDENTITY; }
  88.  
  89.  /**
  90.   * set this transform to a scale
  91.   *
  92.   * @param      sx, x scale
  93.   * @param      sy, y scale
  94.   * @exception
  95.   * @author     michaelp   09-25-97 1:56pm
  96.   **/
  97.  
  98.   void SetToScale(float sx, float sy);
  99.  
  100.  /**
  101.   * set this transform to a translation
  102.   *
  103.   * @param      tx, x translation
  104.   * @param      ty, y translation
  105.   * @exception
  106.   * @author     michaelp   09-25-97 1:56pm
  107.   **/
  108.  
  109.   void SetToTranslate(float tx, float ty);
  110.  
  111.  /**
  112.   * get the translation portion of this transform
  113.   *
  114.   * @param      pt, Point to return translation values in
  115.   * @exception
  116.   * @author     michaelp   09-25-97 1:56pm
  117.   **/
  118.  
  119.   void GetTranslation(float *ptX, float *ptY) { *ptX = m20; *ptY = m21; }
  120.   void GetTranslationCoord(nscoord *ptX, nscoord *ptY) { *ptX = NSToCoordRound(m20); *ptY = NSToCoordRound(m21); }
  121.  
  122.  /**
  123.   * set the translation portion of this transform
  124.   *
  125.   * @param      tx, x translation
  126.   * @param      ty, y translation
  127.   * @exception
  128.   **/
  129.  
  130.   void SetTranslation(float tX, float tY) {
  131.     m20 = tX;
  132.     m21 = tY;
  133.     type |= MG_2DTRANSLATION;
  134.   }
  135.  
  136.  /**
  137.   * get the X translation portion of this transform
  138.   *
  139.   * @param
  140.   * @returns x component of translation
  141.   * @exception
  142.   **/
  143.  
  144.   float GetXTranslation(void)                 { return m20; }
  145.   nscoord GetXTranslationCoord(void)          { return NSToCoordRound(m20); }
  146.  
  147.  /**
  148.   * get the Y translation portion of this transform
  149.   *
  150.   * @param
  151.   * @returns y component of translation
  152.   * @exception
  153.   **/
  154.  
  155.   float GetYTranslation(void)               { return m21; }
  156.   nscoord GetYTranslationCoord(void)        { return NSToCoordRound(m21); }
  157.  
  158.  /**
  159.   * set this matrix and type from another Transform2D
  160.   *
  161.   * @param    aTransform2D is the Transform2D to be copied from
  162.   * @exception
  163.   * @author   michaelp   09-25-97 1:56pm
  164.   **/
  165.  
  166.   void SetMatrix(nsTransform2D *aTransform2D);
  167.  
  168.  /**
  169.   * post-multiply a new Transform
  170.   *
  171.   * @param    newxform new Transform2D
  172.   * @exception
  173.   * @author   michaelp   09-25-97 1:56pm
  174.   **/
  175.  
  176.   void Concatenate(nsTransform2D *newxform);
  177.  
  178.  /**
  179.   * pre-multiply a new Transform
  180.   *
  181.   * @param    newxform new Transform2D
  182.   * @exception
  183.   * @author   michaelp   09-25-97 1:56pm
  184.   **/
  185.  
  186.   void PreConcatenate(nsTransform2D *newxform);
  187.  
  188.  /**
  189.   * apply nontranslation portion of matrix to vector
  190.   *
  191.   * @param    pt  Point to transform
  192.   * @exception
  193.   * @author   michaelp   09-25-97 1:56pm
  194.   **/
  195.  
  196.   void TransformNoXLate(float *ptX, float *ptY);
  197.   void TransformNoXLateCoord(nscoord *ptX, nscoord *ptY);
  198.  
  199.  /**
  200.   * apply matrix to vector
  201.   *
  202.   * @param    pt Point to transform
  203.   * @exception
  204.   * @author   michaelp   09-25-97 1:56pm
  205.   **/
  206.  
  207.   void Transform(float *ptX, float *ptY);
  208.   void TransformCoord(nscoord *ptX, nscoord *ptY);
  209.  
  210.  /**
  211.   * apply matrix to rect
  212.   *
  213.   * @param    rect Rect to transform
  214.   * @exception
  215.   * @author   michaelp   09-25-97 1:56pm
  216.   **/
  217.  
  218.   void Transform(float *aX, float *aY, float *aWidth, float *aHeight);
  219.   void TransformCoord(nscoord *aX, nscoord *aY, nscoord *aWidth, nscoord *aHeight);
  220.  
  221.   /**
  222.    * Scale an array of X/Y coordinates by the X/Y scale factor in the
  223.    * matrix. The scale is done as if the other coordinate were zero.
  224.    *
  225.    * @param aSrc Base of coordinate input array
  226.    * @param aDst Base of coordinate output array
  227.    * @param aNumCoords Number of coordinates to scale
  228.    */
  229.   void ScaleXCoords(const nscoord* aSrc, PRUint32 aNumCoords, PRIntn* aDst);
  230.   void ScaleYCoords(const nscoord* aSrc, PRUint32 aNumCoords, PRIntn* aDst);
  231.  
  232.  /**
  233.   * add a translation to a Transform via x, y pair
  234.   *
  235.   * @param    ptX x value to add as x translation
  236.   * @param    ptY y value to add as y translation
  237.   * @exception
  238.   * @author   michaelp   09-25-97 1:56pm
  239.   **/
  240.  
  241.   void AddTranslation(float ptX, float ptY);
  242.  
  243.  /**
  244.   * add a scale to a Transform via x, y pair
  245.   *
  246.   * @param    ptX x value to add as x scale
  247.   * @param    ptY y value to add as y scale
  248.   * @exception
  249.   * @author   michaelp   09-25-97 1:56pm
  250.   **/
  251.  
  252.   void AddScale(float ptX, float ptY);
  253.  
  254. private:
  255.   nscoord ToCoordRound(float aCoord);
  256. };
  257.  
  258. #endif
  259.